package Year21_Month11.day1105;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Soultion4 {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList();
        if (root == null) {
            return list;
        }
        Stack<TreeNode> stack = new Stack();
        TreeNode cur = root;
        while (stack != null || cur != null) {
            while (cur != null) {
                stack.push(cur);
                cur = cur.left;
            }
            if (cur.right != null) {
                stack.push(cur.right);
            }
            list.add(cur.val);
            cur = stack.pop();
        }
        return list;
    }
}
